function getParentUrl() {
  if (parent !== window) {
    try {
      return parent.location.origin;
    } catch (e) {
      return document.referrer;
    }
  }
}
const isDev = process.env.NODE_ENV === 'development';
const origin = isDev ? 'http://localhost:8127' : getParentUrl();

export function sendMsg2main(payload) {
  top.postMessage(payload, origin);
}
export function showTopMessage(payload) {
  sendMsg2main({
    type: 'showTopMessage',
    params: payload,
  });
}
export default {
  install(Vue) {
    Vue.mixin({
      data() {
        return {};
      },
      methods: {
        sendMsg2main,
        showTopMessage,
      },
    });
  },
};
